package cn.cslg.tieba.domain.dao;

import cn.cslg.tieba.domain.entity.Floor;
import cn.cslg.tieba.domain.entity.FloorWithUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Wu Zhenwei
 * 2017/11/21
 */
@Mapper
public interface FloorDao {

    @Insert("insert into floor(content,floorNo,tieId,userId) values(#{content},#{floorNo},#{tieId},#{userId})")
    @Options(useGeneratedKeys = true, keyProperty = "floorId", keyColumn = "floorId")
    void insert(Floor floor);

    @Select("select * from floor inner join user on floor.userId = user.userId where tieId = #{tieId}")
    List<FloorWithUser> findByTie(Integer tieId);

    @Select("select * from floor inner join user on floor.userId = user.userId where floorId = #{floorId}")
    FloorWithUser findById(Integer floorId);
}
